package org.groupg.filetodb.model.database;


import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

import java.io.Serializable;

/**
 * 表示主键元数据
 */
public class PrimaryKey implements Serializable {
    /**
     * 表目录
     */
    private String tableCat;
    /**
     * 表模式
     */
    private String tableSchem;
    /**
     * 表名
     */
    private String tableName;
    /**
     * 列名
     */
    private String columnName;
    /**
     * 主键中的序列号（从1开始）
     */
    private short keySeq;
    /**
     * 主键约束名称
     */
    private String pkName;

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("tableCat", tableCat)
                .add("tableSchem", tableSchem)
                .add("tableName", tableName)
                .add("columnName", columnName)
                .add("keySeq", keySeq)
                .add("pkName", pkName)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        PrimaryKey that = (PrimaryKey) o;
        return getKeySeq() == that.getKeySeq() && Objects.equal(getTableCat(), that.getTableCat()) && Objects.equal(getTableSchem(), that.getTableSchem()) && Objects.equal(getTableName(), that.getTableName()) && Objects.equal(getColumnName(), that.getColumnName()) && Objects.equal(getPkName(), that.getPkName());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getTableCat(), getTableSchem(), getTableName(), getColumnName(), getKeySeq(), getPkName());
    }

    public String getTableCat() {
        return tableCat;
    }

    public void setTableCat(String tableCat) {
        this.tableCat = tableCat;
    }

    public String getTableSchem() {
        return tableSchem;
    }

    public void setTableSchem(String tableSchem) {
        this.tableSchem = tableSchem;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public short getKeySeq() {
        return keySeq;
    }

    public void setKeySeq(short keySeq) {
        this.keySeq = keySeq;
    }

    public String getPkName() {
        return pkName;
    }

    public void setPkName(String pkName) {
        this.pkName = pkName;
    }
}